package com.weishuang.monitor.employee.jobhandler.impl;

import com.weishuang.monitor.employee.commons.SendUtils;
import com.weishuang.monitor.employee.entity.ServerRamRealTime;
import com.weishuang.monitor.employee.jobhandler.ServerHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import oshi.SystemInfo;
import oshi.hardware.GlobalMemory;

import java.time.LocalDateTime;
import java.time.ZoneOffset;

public class ServerRamRealHandler implements ServerHandler {

    public final static Logger logger = LoggerFactory.getLogger(ServerDiskInfoHandler.class);

    private static final String upServerRamRealUrl = "/api/serversBaseInfo/upRamRealTime";

    /**
     * 服务器信息获取
     */
    @Override
    public void run() {
        SystemInfo si = new SystemInfo();
        GlobalMemory memory = si.getHardware().getMemory();
        memory.getTotal();
        memory.getAvailable();
        memory.getPageSize();

        ServerRamRealTime serverCpuRealTime = new ServerRamRealTime();
        serverCpuRealTime.setTotal(memory.getTotal());
        serverCpuRealTime.setAvailable(memory.getAvailable());
        serverCpuRealTime.setCreatedTime(LocalDateTime.now(ZoneOffset.UTC));
        try {
            String s = SendUtils.sendRequest(upServerRamRealUrl, serverCpuRealTime);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
